package com.ruoyi.web.controller.erp;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Arrays;
import java.util.Base64;

@RestController
@RequestMapping("/test/base64")
public class TestBase64Controller {

    @Autowired
    JdbcTemplate jdbcTemplate;
    @RequestMapping("/test")
    public String[] test(@RequestBody String[] data) {
        StringBuilder sb = new StringBuilder();
        if(data.length > 1){
            for (String datum : data) {
                sb.append(datum+"|");
            }
        }else if(data.length == 1){
            sb.append(data[0]);
        }
        jdbcTemplate.execute("insert into test (image) values('"+sb.toString()+"')");
        return sb.toString().split("\\|");
    }

    @RequestMapping("/{id}")
    public String[] get(@PathVariable Integer id) {
        String data = jdbcTemplate.queryForObject("select image from test where id=?", String.class, id);
        return data.split("\\|");
    }
}
